package spass.raytracer;

import java.util.Collection;

import org.springframework.stereotype.Component;

import spass.geometry.Point;
import spass.geometry.Ray;
import spass.geometry.Vector;
import spass.scene.SceneObject;
import spass.scene.forms.Intersection;
import spass.scene.light.DirectionalLight;

@Component
public class ShadowDetector {

    public double detectShadowAt(Point point, Collection<SceneObject> otherObjects, DirectionalLight directionalLight) {
        Vector lightDirection = directionalLight.getDirection();
        Vector rayDirection = lightDirection.negate();
        Ray ray = new Ray(point, rayDirection);

        for (SceneObject object : otherObjects) {
            Intersection intersection = object.closestIntersection(ray);

            if (intersection != null) {
                return 1;
            }
        }

        return 0;
    }
}
